/*
 * Copyright (c) 2008 Hunter (whywhathow at hotmail dot com)
 * All rights reserved.
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or modify |
   | it under the terms of one of the following licenses:                 |
   |                                                                      |
   |  A) the GNU General Public License as published by the Free Software |
   |     Foundation; either version 2 of the License, or (at your option) |
   |     any later version.                                               |
   |                                                                      |
   |  B) the PHP License as published by the PHP Development Team and     |
   |     included in the distribution in the file: LICENSE                |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of both licenses referred to here.   |
   | If you did not, or have any questions about PHP licensing, please    |
   | contact core@php.net.                                                |
   +----------------------------------------------------------------------+
 */
/*!
 * \file        hte_operator.h
 * \brief       
 * \author      HunterLiu
 * \date        2008-12-4
 * \version     0.1
*/
#ifndef NSL_OPERATOR_H
#define NSL_OPERATOR_H

#include "hte_stack.h"
#include <map>
#include <string>

#define MAX_LENGTH_OF_LONG   18
#define MAX_LENGTH_OF_DOUBLE 32

#ifndef LONG_MAX
#define LONG_MAX             2147483647L
#endif

#ifndef LONG_MIN
#define LONG_MIN             (- LONG_MAX - 1)
#endif


struct REPEAT_ROW
{
	bool bIsTable;
	//std::string strValue;
	std::map<std::string, std::string> mpRow;
};
extern std::multimap<std::string, REPEAT_ROW > g_mpDict;

extern std::deque<NSL_STACK> g_dqContextSwitchStack;
//extern std::deque<NSL_STACK> g_dqRepeatStack;

void convert_to_string(NSL_STRUCT *pstOperator);
int add_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2 );
int div_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2 );
int mul_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2 );
int mod_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2 );
int sub_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2 );
int pval_is_true(NSL_STRUCT *pstOperator);
void hte_start_if (NSL_STRUCT *pstOperator);
int is_greater_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2);
int is_smaller_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2);
int is_equal_function(NSL_STRUCT *pstResult, NSL_STRUCT *pstOperator1, NSL_STRUCT *pstOperator2);

void hte_cs_start_if (NSL_STRUCT *pstExpr);
void hte_cs_end_if ();
void hte_cs_start_else();
void hte_cs_start_elseif (NSL_STRUCT *pstExpr);
void hte_cs_elseif_end_evaluate();
void hte_cs_elseif_start_evaluate();

void hte_repeat_post_statement(NSL_STRUCT *pstToken);
void hte_repeat_add_element(NSL_STRUCT *pstToken, short shTokenType);
void hte_repeat_pre_statement(NSL_STRUCT *pstToken);

#endif
